package com.furtherstar.auth.controller;


import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.furtherstar.auth.controller.dto.PositionQuery;
import com.furtherstar.auth.controller.dto.PositionUserQuery;
import com.furtherstar.auth.dao.model.CorpPosition;
import com.furtherstar.auth.service.CorpPositionService;
import com.github.pagehelper.PageSerializable;
import com.yummy.convention.exception.AssertUtil;
import com.yummy.convention.http.Response;
import com.yummy.web.security.bean.SimpleUser;

@RestController
@RequestMapping("/position")
public class PositionController {
	
	@Autowired
	private CorpPositionService corpPositionService;

	@PostMapping("/add")
	public Response<Long> add(@RequestBody CorpPosition position){
		AssertUtil.notNull(position.getCorpId(),"corpId不能为空");
		AssertUtil.isTrue(StringUtils.isNotBlank(position.getName()),"名称不能为空");
		return Response.success(corpPositionService.add(position));
	}

	@PostMapping("/update")
	public Response<Long> update(@RequestBody CorpPosition position){
		AssertUtil.notNull(position.getId(),"id不能为空");
		return Response.success(corpPositionService.update(position));
	}

	@PostMapping("/enable")
	public Response<Long> enable(@RequestBody CorpPosition position){
		AssertUtil.notNull(position.getId(),"id不能为空");
		return Response.success(corpPositionService.enable(position.getId()));
	}

	@PostMapping("/disable")
	public Response<Long> disable(@RequestBody CorpPosition position){
		AssertUtil.notNull(position.getId(),"id不能为空");
		return Response.success(corpPositionService.disable(position.getId()));
	}

	@PostMapping("/delete")
	public Response<Boolean> delete(@RequestBody CorpPosition position){
		AssertUtil.notNull(position.getId(),"id不能为空");
		return Response.success(corpPositionService.delete(position.getId()));
	}

	@PostMapping("/page")
	public Response<PageSerializable<CorpPosition>> page(@RequestBody PositionQuery positionQuery){
		return Response.success(corpPositionService.pageQuery(positionQuery));
	}

	@PostMapping("/page/available")
	public Response<PageSerializable<CorpPosition>> pageAvaliable(@RequestBody PositionQuery positionQuery){
		return Response.success(corpPositionService.pageAvaliable(positionQuery));
	}

	@PostMapping("/user/page")
	public Response<PageSerializable<SimpleUser>> page(@RequestBody PositionUserQuery positionUserQuery){
		AssertUtil.notNull(positionUserQuery.getPositionId(),"职位不能为空");
		return Response.success(corpPositionService.pageUsers(positionUserQuery));
	}
}
